<?php
    if (file_exists("../users/".$_POST[username])){}
    else{
        if (!mkdir('../users/'.$_POST[username], 0, true)) {
            die('Failed to create folders...');
        }
    }

    require_once 'database.php';
    $_nameFoto = $_FILES["foto"]["name"];

	$usr = $_POST['username'];
	$email = $_POST['email'];
	$hasil = database::query('SELECT * FROM user WHERE Email="'.$email.'"');
	$hasil2 = database::query('SELECT * FROM user WHERE Username="'.$usr.'"');
	
	if (mysql_num_rows($hasil)>0)
	{
		echo 'Email tersebut sudah digunakan untuk register user lain';
	}
	else if (mysql_num_rows($hasil2)>0)
	{
		echo 'Username tersebut sudah digunakan untuk register user lain';
	}
	else
	{
		database::query("INSERT INTO User (Username, Password, Nama, Email, TanggalLahir) VALUES ('$_POST[username]','". md5($_POST[password])."', '$_POST[nama]', '$_POST[email]', '$_POST[lahir]')");
		//database::query("INSERT INTO Foto (Username, Filefoto, IDKategori, Deskripsi) VALUES ('$_POST[username]','$_nameFoto', 2, 'No Description')");

		//$idFoto = mysql_query("SELECT IdFoto FROM Foto SORT DESCENDING ");
		
	   //require 'uploader.php';
	   //uploader::uploadProfPic($_POST['username']);
	   echo 'Selamat!<br/>toet toet toet!<br/>Register berhasil!!!';
   }
?>
